import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {SystemConfigService} from '@core/services/system-config.service';

@Component({
  selector: 'app-staffs-list',
  templateUrl: './staffs-list.component.html',
  styleUrls: ['./staffs-list.component.less']
})
export class StaffsListComponent implements OnInit {

  dataSet = [];
  isVisibleMiddle = false;

  constructor(private activatedRoute: ActivatedRoute, private router: Router, private systemService: SystemConfigService) {}

  ngOnInit() {
    this.getStaffPage({pageNum: 1, pageSize: 10});
  }
  // 获取列表页员工
  getStaffPage(p) {
    return this.systemService.getStaffPage(p).then((response: any) => {
      console.log(response);
      this.dataSet = response.data;
    });
  }

  // 删除员工
  delStaff(id) {
    return this.systemService.delStaff(id).then((response: any) => {
      console.log('response++++++++++++++++++++++');
      console.log('response+++++++++++++++++++++++++++++++++');
      this.ngOnInit();
    });
  }

  // 删除弹出模态框
  showModalMiddle(): void {
    this.isVisibleMiddle = true;
  }

  // 模态框中点击确认删除数据
  handleOkMiddle(id): void {
    console.log('click ok');
    this.delStaff(id);
    this.isVisibleMiddle = false;
  }

  // 模态窗中点击隐藏
  handleCancelMiddle(): void {
    this.isVisibleMiddle = false;
  }
  // 进入新增页面
  goStaffAdd() {
    this.router.navigateByUrl('/staff/staffs-add');
  }
}
